#include "linklist.h"
#include <stdlib.h>

STATUS NewLinkList(LinkList **list)
{
    LinkList *head = (LinkList *)malloc(sizeof(LinkList));
    if (head == NULL) {
        return RET_STATUS_ERR;
    }
    head->next = NULL;
    head->data = 0;
    *list      = head;
    return RET_STATUS_OK;
}

STATUS append(LinkList *head, LinkList *jointNode)
{
    while (head->next != NULL) {
        head = head->next;
    }
    LinkList *node = (LinkList *)malloc(sizeof(LinkList));
    if (node == NULL) {
        return RET_STATUS_ERR;
    }
    head->next = node;
    node->data = jointNode->data;
    node->next = NULL;

    return RET_STATUS_OK;
}
STATUS freeLinkList(LinkList *head)
{
    while (head->next != NULL) {
        LinkList *node = head->next;
        head->next     = node->next;
        free(node);
    }

    return RET_STATUS_OK;
}

void PrintLinkList(LinkList *head)
{
    while (head != NULL) {
        printf("current data: [%d]\n", head->data);
        head = head->next;
    }

    return;
}
